using UnityEngine;

public class GroundSpawner : MonoBehaviour
{
    [Header("Spawning")]
    [SerializeField] private GameObject[] groundPrefab;
    [SerializeField] private Vector2 spawnPos;

    void Start()
    {
        for (int i = 0; i < 3; i++) {
            SpawnGround();
        }
    }

    public void SpawnGround() {

        if (GameManager.instance == null) {
            return;
        }

        if (GameManager.instance.isGameActive == false) {
            return;
        }
        else {
            int prefabIndex = Random.Range(0, groundPrefab.Length);
            GameObject tempGround = Instantiate(groundPrefab[prefabIndex], spawnPos, Quaternion.identity);
            spawnPos = tempGround.transform.GetChild(1).transform.position;
        }
    }
}
